export default function debounce<P extends any[]>(func: (...params: P) => void, waitMs: number) {
  let timer: NodeJS.Timeout;

  return (...params: P) => {
    if (timer) {clearTimeout(timer);}

    timer = setTimeout(() => {
      func(...params);
    }, waitMs);
  };
}